package com.codefish.codefish_blog.ajax;

import lombok.Data;

import java.util.HashMap;

/**
 * simple ajax请求结果
 *
 * @author codefish
 * @version 1.0
 * @date 2022/04/04 下午 11:03
 */
@Data
public class AjaxResult {
    /**
     * 请求结果
     */
    private Boolean result;
    /**
     * 响应消息
     */
    private String message;
    /**
     * 成功操作返回的数据
     */
    private Object data;


    protected AjaxResult(boolean result, String message, Object data) {
        this.result = result;
        this.message = message;
        this.data = data;
    }

    protected AjaxResult(boolean result, String message) {
        this.result = result;
        this.message = message;
        this.data = null;
    }

    /**
     * 操作失败AjaxResult工厂
     */
    public static AjaxResult fail(String message) {
        return new AjaxResult(false, message);
    }

    public static AjaxResult fail() {
        return new AjaxResult(false, "操作失败");
    }

    /**
     * 操作成功AjaxResult工厂
     */
    public static AjaxResult success(String message, Object data) {
        return new AjaxResult(true, message, data);
    }

    public static AjaxResult success(Object data) {
        return new AjaxResult(true, "操作成功", data);
    }

    public static AjaxResult success(String message) {
        return new AjaxResult(true, message);
    }

    public static AjaxResult success() {
        return new AjaxResult(true, "操作成功");
    }
}
